package util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class TimestampUtil {
	SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");

	public Timestamp parseTimestampHoraInicial(String data)
			throws ParseException {

		Calendar cal = new GregorianCalendar();
		cal.setTimeInMillis(df.parse(data).getTime());

		int dia = cal.get(Calendar.DAY_OF_MONTH);
		int mes = cal.get(Calendar.MONTH) + 1;
		int ano = cal.get(Calendar.YEAR);

		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

		return new Timestamp(sdf.parse(
				dia + "/" + mes + "/" + ano + " 00:00:00").getTime());

	}

	public Timestamp parseTimestampHoraFinal(String data)
			throws ParseException {

		Calendar cal = new GregorianCalendar();
		cal.setTimeInMillis(df.parse(data).getTime());

		int dia = cal.get(Calendar.DAY_OF_MONTH);
		int mes = cal.get(Calendar.MONTH) + 1;
		int ano = cal.get(Calendar.YEAR);

		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

		return new Timestamp(sdf.parse(
				dia + "/" + mes + "/" + ano + " 23:59:59").getTime());

	}
}
